package xujiwen.transport.servlet;

import xujiwen.transport.bean.Station;
import xujiwen.transport.Mgr.StationMgr;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class for Servlet: Register
 * 
 */
public class ModifStation extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public ModifStation() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	@Override
	protected void doGet(final HttpServletRequest request,
			final HttpServletResponse response) throws ServletException,
			IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	@Override
	protected void doPost(final HttpServletRequest request,final HttpServletResponse response) throws ServletException,IOException {
		StationMgr sm = new StationMgr();
		// 指明编码
		request.setCharacterEncoding("utf-8"); 
		//System.out.println(password + "\t" + email + "\t");
		try {
			final String sname = request.getParameter("sname");
			final int lid = Integer.parseInt(request.getParameter("leader"));
			
			final String address = request.getParameter("address");
			final String phone = request.getParameter("phone");
			final int sid = Integer.parseInt(request.getParameter("sid"));
			
			
			final Station station = new Station();
		
			station.setSName(sname);
			station.setLid(lid);
			station.setAddress(address);
			station.setPhone(phone);
			station.setSid(sid);
			sm.Update(station);
			System.out.println("修改站点成功");
		} catch(final NumberFormatException nfex){
			//response.sendRedirect("err.jsp");
			System.out.println("提交错误");			
			return ;
		}
		response.sendRedirect("admin/stationMgr.jsp?searchStr=");
	}
}